package spring.test1;

import com.blackhorse.dao.AccountDao;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Demo2_Scope {
    ApplicationContext applicationContext;

    @Before
    public void setUp() {
        //1.获取spring核心容器
        applicationContext = new ClassPathXmlApplicationContext("ioc/applicationContext.xml");
    }

    @Test
    public void testSingleton() {
        AccountDao singletonAccountDao = (AccountDao) applicationContext.getBean("singletonAccountDao");
        AccountDao singletonAccountDao2 = (AccountDao) applicationContext.getBean("singletonAccountDao");
        System.out.println("两次获取bean是否为同一个:" + (singletonAccountDao == singletonAccountDao2));
    }

    @Test
    public void testPrototype(){
        AccountDao prototypeAccountDao = (AccountDao) applicationContext.getBean("prototypeAccountDao");
        AccountDao prototypeAccountDao2 = (AccountDao) applicationContext.getBean("prototypeAccountDao");
        System.out.println("两次获取bean是否为同一个:" + (prototypeAccountDao == prototypeAccountDao2));
    }
}
